﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.CMS263.BLL;
using Com.CMS263.PO;
using Com.CMS263.Util;
using System.IO;

namespace Com.CMS263.Web.manage.TvStation
{
    public partial class addTvStation : System.Web.UI.Page
    {
        TVstationBLL tvBll = new TVstationBLL();
        public IList<Province> provlist = new List<Province>();
        ProvinceBLL proBll = new ProvinceBLL();
        cityBLL cityBll = new cityBLL();
        AreaBLL areaBll = new AreaBLL();
        protected void Page_Load(object sender, EventArgs e)
        {            
            if (!Page.IsPostBack)
            {
                BindData();
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strDay = DateTime.Now.ToString("yyyy-MM-dd");
            string savePath = Server.MapPath("/ArtUpFile/" + strDay);
            if (!Directory.Exists(savePath))
            {
                Directory.CreateDirectory(savePath);
            }
            string LogoPic = strDay + "/" + UpLoadFileUtil.UpLoadFile(Request.Files["LogoPic"], savePath);
            string BigPic = strDay + "/" + UpLoadFileUtil.UpLoadFile(Request.Files["BigPic"], savePath);
            string name = StringUtil.checkStr(Request["Name"]);
            string telePhone = StringUtil.checkStr(Request["telePhone"]);
            string proCode= Request["txtProvince"];
            proBll.entity = (Province)proBll.FindModelByCode("Province", proCode);
            string cityCode = Request["txtCity"];
            cityBll.entity = (City)cityBll.FindModelByCode("City", cityCode);
            string areaCode = Request["txtArea"];
            areaBll.entity = (Area)areaBll.FindModelByCode("Area", areaCode);
            string AdressRo = StringUtil.checkStr(Request["AdressRo"]);

            tvBll.tv.AdressRo = AdressRo;
            string address = proBll.entity.Name + cityBll.entity.Name + areaBll.entity.Name + AdressRo;

            tvBll.tv.Name = name;
            tvBll.tv.LogoPic = LogoPic;
            tvBll.tv.Address = address;
            tvBll.tv.BigPic = BigPic;
            tvBll.tv.TelePhone = telePhone;
            tvBll.tv.ProvinceCode = proBll.entity.Code;
            tvBll.tv.CityCode = cityBll.entity.Code; 
            tvBll.tv.AreaCode = areaBll.entity.Code ;
            if (tvBll.Add()) {
                StringUtil.Alert("添加成功！", "tvStationList.aspx");
            }
            else
            {
                StringUtil.Alert("添加失败，请重新添加！", "-1");
            }
            
        }
        ProvinceBLL provbll = new ProvinceBLL();
        public void BindData()
        {
            provlist = provbll.GetAllProvince();
        }
    }
}
